package com.ganzalang.gmall.objectcopy.deep.factory;

import com.ganzalang.gmall.objectcopy.deep.domain.Address;
import com.ganzalang.gmall.objectcopy.deep.domain.Tax;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;

/**
 * @description: 深拷贝
 * @author: Ganzalang
 * @Date 2021/7/5 20:54
 */
@Slf4j
public class DeepCopy {

    public static void main(String[] args) throws CloneNotSupportedException {
        Tax taxA = new Tax();
        Address addrA = new Address();
        taxA.setRate(new BigDecimal("1.00"));
        taxA.setAddress(addrA);
        addrA.setCountryCode("CN");
        addrA.setCountryCode("GZ");

        Tax taxB = (Tax) taxA.clone();
        Address addrB = taxB.getAddress();
        addrB.setCountryCode("AU");
        addrB.setChildCode("BS");
        taxB.setAddress(addrB);
        taxB.setRate(new BigDecimal("2.00"));

        log.info("taxA's hashCode: {}, address's hashCode: {}, object value: {}", taxA.hashCode(), taxA.getAddress().hashCode(), taxA);
        log.info("taxB's hashCode: {}, address's hashCode: {}, object value: {}", taxB.hashCode(), taxB.getAddress().hashCode(), taxB);

    }
}
